package com.hcryan.djm.controller.api;

import com.hcryan.djm.config.BaiduMapConfig;
import com.hcryan.djm.feign.BaiduMapApi;
import com.hcryan.djm.feign.response.DrivingResp;
import com.hcryan.djm.feign.response.LocationSearchResp;
import com.hcryan.djm.result.WebResult;
import com.hcryan.djm.service.BaiduMapService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ryanwdj
 * @since 2025/2/22
 */

@RestController
@RequestMapping("/api/baidu-map/")
@Slf4j
@Validated
@Api("百度地图api接口")
public class BaiduMapController {

    @Autowired
    private BaiduMapConfig baiduMapConfig;
    @Autowired
    private BaiduMapApi baiduMapApi;
    @Autowired
    private BaiduMapService baiduMapService;

    @ApiOperation("地点检索")
    @GetMapping("/location-search")
    public WebResult<LocationSearchResp> searchLocation(
            @RequestParam String query,
            @RequestParam String region
    ){
        LocationSearchResp resp = baiduMapApi.locationSearch(baiduMapConfig.getAk(), query, region, "json");
        return WebResult.success(resp);
    }

    @ApiOperation("驾车路线规划")
    @GetMapping("/driving")
    public WebResult<DrivingResp> searchDriving(
            @RequestParam String origin,
            @RequestParam(required = false) String waypoints,
            @RequestParam String destination
            ){

        DrivingResp resp = baiduMapService.searchDriving(origin, waypoints, destination);
        return WebResult.success(resp);
    }
}
